/**
  其他境外交流项目-管理员查看所有
*/
<template>
    <div class="project-manage-container">
        <div v-if="indexKey === 1">
            <condition-card
                @reset="reset"
                @search="onSubmit"
                label-position="right"
                label-width="150px"
            >
                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <!-- 项目子类别 -->
                        <el-form-item
                            :label="$t('projectManage.projectSubCategory')"
                            prop="projectSubCategory"
                        >
                            <el-select
                                v-model="queryForm.condition.projectSubCategory"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.projectSubCategory"
                                    :key="item.id"
                                    :label="item.typeName"
                                    :value="item.id"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 学院 -->
                        <el-form-item
                            :label="$t('externamExchangeBase.college')"
                            prop="studentFaculty"
                        >
                            <el-select
                                :disabled="auditMode === '2'"
                                filterable
                                v-model="queryForm.condition.studentFaculty"
                                @change="changeCollege"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.studentFaculty"
                                    :key="item.key"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 专业 -->
                        <el-form-item
                            :label="$t('externamExchangeBase.profession')"
                            prop="studentProfession"
                        >
                            <el-select
                                v-model="queryForm.condition.studentProfession"
                                filterable
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.studentProfession"
                                    :key="item.key"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <!-- 国家地区 -->
                        <el-form-item
                            :label="$t('exchangeProjectAudit.projectNationCode')"
                            prop="projectNationCode"
                        >
                            <el-select
                                v-model="queryForm.condition.projectNationCode"
                                filterable
                                @change="changeNation"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.projectNationCode"
                                    :key="item.key"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 合作大学 -->
                        <el-form-item
                            :label="$t('externamExchangeBase.cooperativeUniversity')"
                            prop="projectCollegeId"
                        >
                            <el-select
                                v-model="queryForm.condition.projectCollegeId"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.projectCollegeId"
                                    :key="item.id"
                                    :label="item.collegeName"
                                    :value="item.id"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 项目开始时间 -->
                        <el-form-item
                            :label="$t('projectApplication.projectStartTime')"
                            prop="projectStartTimeStr"
                        >
                            <el-date-picker
                                style="width: 100%"
                                v-model="queryForm.condition.projectStartTimeStr"
                                type="date"
                                value-format="yyyy-MM-dd"
                                :placeholder="$t('graduateBase.chooseDateAndTime')"
                                :picker-options="xmkssjPickerOptions"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <!-- 项目结束时间 -->
                        <el-form-item
                            :label="$t('projectApplication.projectEndTime')"
                            prop="projectEndTimeStr"
                        >
                            <el-date-picker
                                style="width: 100%"
                                v-model="queryForm.condition.projectEndTimeStr"
                                type="date"
                                value-format="yyyy-MM-dd"
                                :placeholder="$t('graduateBase.chooseDateAndTime')"
                                :picker-options="xmjssjPickerOptions"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            :label="$t('exchangeProjectAudit.studentParam')"
                            prop="studentParam"
                        >
                            <el-input
                                :placeholder="$t('common.pla.pleaseInput')"
                                v-model="queryForm.condition.studentParam"
                                clearable
                                :maxlength="32"
                                style="width: 100%"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 出国审核状态 -->
                        <el-form-item
                            :label="$t('exchangeProjectAudit.goAbroadAuditStatus')"
                            prop="applyStatus"
                        >
                            <el-select
                                v-model="queryForm.condition.applyStatus"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.applyStatus"
                                    :key="item.key"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <!-- 报销审核状态 -->
                        <el-form-item
                            :label="$t('exchangeProjectAudit.goHomeReimbursementStatus')"
                            prop="backApplyStatus"
                        >
                            <el-select
                                v-model="queryForm.condition.backApplyStatus"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.backApplyStatus"
                                    :key="item.key"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 项目名称 -->
                        <el-form-item
                            :label="$t('projectManage.projectName')"
                            prop="projectMngmtName"
                        >
                            <el-input
                                :placeholder="$t('common.pla.pleaseInput')"
                                v-model="queryForm.condition.projectMngmtName"
                                clearable
                                :maxlength="32"
                                style="width: 100%"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- 录取状态 -->
                        <el-form-item
                            :label="$t('nationGovernAdmission.admissionStatus')"
                            prop="participantPass"
                        >
                            <el-select
                                v-model="queryForm.condition.participantPass"
                                :placeholder="$t('common.pla.pleaseSelect')"
                                clearable
                                style="width: 100%;"
                            >
                                <el-option
                                    v-for="item in options.participantPass"
                                    :key="item.key"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </condition-card>
            <el-card
                shadow="never"
                v-loading="loading"
                body-style="padding: 24px;"
                class="card-margin"
            >
                <h1 class="condition-title">{{$t('otherOverseasExchange.otherOverseasExchangePro')}}</h1>
                <div class="edu-opertion-bar sub-title">
                    <div class="float-right" style="display: flex;">
                        <el-button
                            v-if="permitToExport"
                            type="primary"
                            @click="exportProject()"
                        >{{$t('common.btn.export')}}</el-button>
                    </div>
                </div>
                <edu-table
                    :pagination="false"
                    :order="true"
                    :tooltipEffect="tooltipEffect"
                    stripe
                    :data="dataList"
                    size="mini"
                    @selection-change="handleSelectionChange"
                >
                    <edu-table-column
                        :label="$t('externamExchangeBase.studentId')"
                        prop="studentId"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('externamExchangeBase.studentName')"
                        prop="studentName"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('externamExchangeBase.college')"
                        prop="studentFacultyName"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('externamExchangeBase.profession')"
                        prop="studentProfessionName"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('projectManage.projectSubCategory')"
                        prop="projectSubCategoryName"
                        width="100"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('projectManage.projectName')"
                        prop="projectMngmtName"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('interdisciplinaryManagement.country')"
                        prop="projectNationName"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.changes.length > 0">
                                <span
                                    v-if="scope.row.changes[0].nationChanged"
                                    style="color: red;"
                                >{{ scope.row.changes[0].countryRegion }}</span>
                                <span v-else>{{ scope.row.projectNationName }}</span>
                            </div>
                            <div v-else>{{ scope.row.projectNationName }}</div>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('externamExchangeBase.cooperativeUniversity')"
                        prop="projectCollegeCn"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.changes.length > 0">
                                <span
                                    v-if="scope.row.changes[0].collegeChanged"
                                    style="color: red;"
                                >{{ scope.row.changes[0].cooperateUniversity }}</span>
                                <span v-else>{{ scope.row.projectCollegeCn }}</span>
                            </div>
                            <div v-else>{{ scope.row.projectCollegeCn }}</div>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.projectStartTime')"
                        prop="projectStartTime"
                        width="110"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.changes.length > 0">
                                <span
                                    v-if="scope.row.changes[0].startTimeChanged"
                                    style="color: red;"
                                >{{ scope.row.changes[0].projectStartTime }}</span>
                                <span v-else>{{ scope.row.projectStartTime }}</span>
                            </div>
                            <div v-else>{{ scope.row.projectStartTime }}</div>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.projectEndTime')"
                        prop="projectEndTime"
                        width="110"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.changes.length > 0">
                                <span
                                    v-if="scope.row.changes[0].endTimeChanged"
                                    style="color: red;"
                                >{{ scope.row.changes[0].projectEndTime }}</span>
                                <span v-else>{{ scope.row.projectEndTime }}</span>
                            </div>
                            <div v-else>{{ scope.row.projectEndTime }}</div>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.realStartTime')"
                        prop="realStartTime"
                        width="110"
                    >
                        <template slot-scope="scope">
                            <span v-if="scope.row.back">{{ scope.row.back.realStartTime }}</span>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.realEndTime')"
                        prop="realEndTime"
                        width="110"
                    >
                        <template slot-scope="scope">
                            <span v-if="scope.row.back">{{ scope.row.back.realEndTime }}</span>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.projectStudyAbroadContent')"
                        prop="projectStudyAbroadContent"
                    ></edu-table-column>
                    <edu-table-column
                        :label="$t('exchangeProjectAudit.experts')"
                        prop="applyExpertTeacherName"
                    >
                        <template slot-scope="scope">
                            <span
                                v-if="scope.row.applyExpertTeacherName"
                            >{{ scope.row.applyExpertTeacherName }}</span>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.goAbroadAuditStatus')"
                        prop="applyStatus"
                        width="135"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                :type="scope.row.applyStatus | getApplyStatusType"
                            >{{ scope.row.applyStatus | goAbroadAuditStatus }}</el-tag>
                        </template>
                    </edu-table-column>
                    <!-- 下一级审批人 -->
                    <edu-table-column
                        :label="$t('externamExchangeBase.nextAuditPerson')"
                        prop="approverNameCopy"
                        width="110"
                    ></edu-table-column>
                    <edu-table-column :label="$t('common.text.operation')" prop="operation" fit>
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="selectGoAbroad(scope.row)"
                            >{{$t('message.Look')}}</el-button>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('exchangeProjectAudit.reimbursementStatus')"
                        prop="returnHomeReimbursement"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.back"
                                :type="scope.row.back.applyStatus | getApplyStatusType"
                            >{{ scope.row.back.applyStatus | returnHomeReimbursement }}</el-tag>
                        </template>
                    </edu-table-column>
                    <!-- 报销下一级审批人 -->
                    <edu-table-column
                        :label="$t('externamExchangeBase.baoxiaoNextAuditPerson')"
                        prop="approverName"
                        width="135"
                    >
                        <template slot-scope="scope">
                            <span v-if="scope.row.back">{{ scope.row.back.approverName }}</span>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('projectApplication.baoxiaoAndBaoDaoOperate')"
                        fit
                        width="110"
                    >
                        <template slot-scope="scope">
                            <el-button
                                v-if="scope.row.back && scope.row.back.applyStatus !== 1 && scope.row.back.applyStatus !== 5"
                                type="text"
                                @click="selectReturnHome(scope.row)"
                            >{{$t('message.Look')}}</el-button>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        :label="$t('nationGovernAdmission.admissionStatus')"
                        prop="participantPass"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                :type="scope.row.participantPass | getAdmissionType"
                            >{{ scope.row.participantPass | participantPass }}</el-tag>
                        </template>
                    </edu-table-column>
                </edu-table>
                <el-row type="flex" class="row-bg" justify="end">
                    <el-col>
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[20, 40, 80, 100]"
                            :page-size="queryForm.pageSize_"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="queryForm.total_"
                            style="float:right;margin-top:10px"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </el-card>
        </div>
        <!-- 查看出国详情开始 -->
        <div v-if="indexKey === 2">
            <go-abroad-for-select
                :applyId="applyId"
                :projectSubCategory="projectSubCategory"
                :projectStartTime="projectStartTime"
                :projectEndTime="projectEndTime"
                @change-project-index="changeProjectIndex"
            ></go-abroad-for-select>
        </div>
        <!-- 查看出国详情结束 -->
        <!-- 查看回国详情开始 -->
        <div v-if="indexKey === 3">
            <return-home-select
                :showProcess="showProcess"
                :applyId="applyId"
                :projectStartTime="projectStartTime"
                :projectEndTime="projectEndTime"
                :projectSubCategory="projectSubCategory"
                :backId="backId"
                @change-project-index="changeProjectIndex"
            ></return-home-select>
        </div>
        <!-- 查看回国详情结束 -->
        <edu-export-dialog
            :disabled="exportButton"
            :title="$t('message.prompt')"
            ref="downloadRef"
            :data="exportResult"
        ></edu-export-dialog>
    </div>
</template>
<script>
import baseUrl from 'common/src/api/externalExchange/env'
import externalExchangeApi from 'common/src/api/externalExchange/externalExchange'
import goAbroadForSelect from './goAbroadForSelect'
import returnHomeSelect from './returnHomeSelect'
import innovativeApi from 'common/src/api/innovative/innovative'
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
export default {
    components: {
        'go-abroad-for-select': goAbroadForSelect,
        'return-home-select': returnHomeSelect
    },
    data() {
        return {
            auths: [],
            permitToExport: true,
            showProcess: false,
            indexKey: 1,
            applyId: '',
            backId: '',
            multipleSelection: [],
            queryForm: {
                pageNum_: 1,
                pageSize_: 20,
                total_: 0,
                condition: {
                    projectSubCategory: '',
                    studentFaculty: '',
                    studentProfession: '',
                    projectNationCode: '',
                    projectCollegeId: '',
                    projectStartTimeStr: '',
                    projectEndTimeStr: '',
                    studentParam: '',
                    applyStatus: '',
                    backApplyStatus: '',
                    projectMngmtName: '',
                    participantPass: ''
                }
            },
            dialogMode: 'add',
            options: {
                // 项目子类别
                projectSubCategory: [],
                // 学院
                studentFaculty: [],
                // 专业
                studentProfession: [],
                // 国家
                projectNationCode: [],
                // 合作大学
                projectCollegeId: [],
                // 出国审核状态
                applyStatus: [
                    {
                        key: 0,
                        label: '不通过',
                        value: 0
                    },
                    {
                        key: 2,
                        label: '已提交',
                        value: 2
                    },
                    {
                        key: 3,
                        label: '待审核',
                        value: 3
                    },
                    {
                        key: 4,
                        label: '通过',
                        value: 4
                    }
                ],
                // 报销审核状态
                backApplyStatus: [
                    {
                        key: 2,
                        label: '已提交',
                        value: 2
                    },
                    {
                        key: 3,
                        label: '待审核',
                        value: 3
                    },
                    {
                        key: 4,
                        label: '通过',
                        value: 4
                    }
                ],
                // 录取状态
                participantPass: [
                    {
                        key: 0,
                        label: '未评',
                        value: 0
                    },
                    {
                        key: 1,
                        label: '已录取',
                        value: 1
                    },
                    {
                        key: 2,
                        label: '未录取',
                        value: 2
                    },
                    {
                        key: 3,
                        label: '放弃',
                        value: 3
                    }
                ]
            },
            dataList: [],
            exportButton: false,
            exportResult: null,
            projectSubCategory: '',
            projectStartTime: '',
            projectEndTime: ''
        }
    },
    filters: {
        goAbroadAuditStatus(val) {
            switch (val) {
                case 0:
                    return '不通过'
                case 1:
                    return '草稿'
                case 2:
                    return '已提交'
                case 3:
                    return '待审核'
                case 4:
                    return '通过'
                case 5:
                    return '驳回'
                default:
                    return val
            }
        },
        getApplyStatusType(val) {
            switch (val) {
                case 0:
                    return 'danger'
                case 1:
                    return 'info'
                case 2:
                    return 'info'
                case 3:
                    return 'info'
                case 4:
                    return 'success'
                case 5:
                    return 'warning'
                case 6:
                    return 'success'
                default:
                    return val
            }
        },
        getAdmissionType(val) {
            switch (val) {
                case 0:
                    return 'info'
                case 1:
                    return 'success'
                case 2:
                    return 'info'
                case 3:
                    return 'info'
                default:
                    return val
            }
        },
        returnHomeReimbursement(val) {
            switch (val) {
                case 1:
                    return '草稿'
                case 2:
                    return '已提交'
                case 3:
                    return '待审核'
                case 4:
                    return '通过'
                case 5:
                    return '驳回'
                case 6:
                    return '已完成'
                default:
                    return val
            }
        },
        participantPass(val) {
            switch (val) {
                case 0:
                    return '未评'
                case 1:
                    return '已录取'
                case 2:
                    return '未录取'
                case 3:
                    return '放弃'
                default:
                    return val
            }
        }
    },
    computed: {
        // 项目开始时间
        xmkssjPickerOptions() {
            let _this = this
            return {
                disabledDate: value => {
                    if (_this.queryForm.condition.projectEndTimeStr) {
                        // 项目开始时间必须小于项目截止时间
                        if (
                            value.getTime() >
                            new Date(_this.queryForm.condition.projectEndTimeStr).getTime()
                        ) {
                            return true
                        }
                    }
                    return false
                }
            }
        },
        // 项目结束时间
        xmjssjPickerOptions() {
            let _this = this
            return {
                disabledDate: value => {
                    if (_this.queryForm.condition.projectStartTimeStr) {
                        // 评分截止时间必须大于评分开始时间
                        if (
                            value.getTime() + 24 * 60 * 60 * 1000 <
                            new Date(_this.queryForm.condition.projectStartTimeStr).getTime()
                        ) {
                            return true
                        }
                    }
                    return false
                }
            }
        }
    },
    async created() {
        // 获取当前用户auths权限
        if (localStorage.getItem('sessiondata')) {
            if (JSON.parse(localStorage.getItem('sessiondata')).auths) {
                this.auths = JSON.parse(localStorage.getItem('sessiondata')).auths
            }
        }
        this.initOptions()
        this.getAllCollege()
        // 获取项目子类别
        externalExchangeApi
            .getXMZLBOptions({
                selectFlag: 0,
                parentId: 2
            })
            .then(res => {
                if (res.code === 200 && res.data.length > 0) {
                    this.options.projectSubCategory = res.data
                }
            })
        this.onSubmit()
    },
    methods: {
        // 校验特殊字符$
        checkSpecial(rule, value, callback) {
            let regEn = /[`$]/im
            if (regEn.test(value)) {
                callback(new Error(this.$t('graduateBase.specialText')))
            } else {
                callback()
            }
        },
        async initOptions() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [
                    'G_GJQU' // 国家
                ]
            }
            await queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        projectNationCode: 'G_GJQU' // 国家
                    },
                    res.data,
                    this.options
                )
            })
        },
        reset() {
            Object.keys(this.queryForm.condition).forEach(
                key => (this.queryForm.condition[key] = '')
            )
            this.options.studentProfession = []
            this.options.projectCollegeId = []
            this.onSubmit()
        },
        getListData() {
            externalExchangeApi.selectExternalExchangeRecord(this.queryForm).then(res => {
                this.dataList = res.data.list
                this.queryForm.total_ = res.data.total_
            })
        },
        onSubmit() {
            this.queryForm.pageNum_ = 1
            this.getListData()
        },
        handleSelectionChange(val) {
            this.multipleSelection = val
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val
            this.getListData()
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val
            this.getListData()
        },
        // 获取学院
        getAllCollege() {
            // innovativeApi.getAllFaculty().then(res => {
            //   if (res.code === 200) {
            //     if (Array.isArray(res.data) &&  res.data.length > 0) {
            //       res.data.map(item => {
            //         this.options.studentFaculty.push({
            //           label: (this.$store.getters.language === 'cn' || !this.$store.getters.language) ? item.deptName : item.deptNameEn,
            //           value: item.deptCode,
            //           key: item.deptCode
            //         });
            //       });
            //     }
            //   }
            // });
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [
                    'X_YX' // 学院
                ]
            }
            queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        studentFaculty: 'X_YX' // 学院
                    },
                    res.data,
                    this.options
                )
            })
        },
        // 修改国家
        changeNation(val) {
            this.queryForm.condition.projectCollegeId = ''
            this.options.projectCollegeId = []
            // 获取合作大学
            if (val) {
                externalExchangeApi
                    .getCollegeByNationCode({
                        code: val
                    })
                    .then(res => {
                        if (res.code === 200) {
                            this.options.projectCollegeId = res.data
                        }
                    })
            } else {
                this.options.projectCollegeId = []
            }
        },
        // 修改学院
        changeCollege(val) {
            this.options.studentProfession = []
            this.queryForm.condition.studentProfession = ''
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['G_ZY'],
                filter: {
                    prefix: [val],
                    specilaCode: 'XY2ZY',
                    facultys: [val]
                }
            }
            queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        studentProfession: 'G_ZY' // 专业
                    },
                    res.data,
                    this.options
                )
            })
        },
        // 导出异步-批量
        batchDelayRequest(key) {
            setTimeout(() => {
                externalExchangeApi.downloadGetKey(key).then(res => {
                    this.exportResult = res.data
                    if (res.code == 200 && res.data.status) {
                        this.exportButton = false
                        let path = `${baseUrl}/export/file?path=` + res.data.path
                        // window.open(path);
                        window.location.href = path
                        this.$message.success(this.$t('result.exportSuccessfully'))
                        this.$refs.downloadRef.close()
                    } else {
                        this.batchDelayRequest(key)
                    }
                })
            }, 2000)
        },
        // Normal导出异步-批量
        batchNormalDelayRequest(key) {
            externalExchangeApi.downloadGetKey(key).then(res => {
                this.exportResult = res.data
                if (res.code == 200 && res.data.status) {
                    this.exportButton = false
                    let path = `${baseUrl}/export/file?path=` + res.data.path
                    // window.open(path);
                    window.location.href = path
                    this.$message.success(this.$t('result.exportSuccessfully'))
                    this.$refs.downloadRef.close()
                } else {
                    this.batchDelayRequest(key)
                }
            })
        },
        // 导出数据
        exportProject() {
            if (this.dataList.length === 0) {
                this.$message.error(this.$t('externamExchangeBase.exportNoData'))
                return
            }
            let applyIdList = []
            if (this.multipleSelection.length > 0) {
                applyIdList = this.multipleSelection.map(value => {
                    return value.applyId
                })
            }
            this.exportResult = null
            this.$refs.downloadRef.open()
            this.exportButton = true
            externalExchangeApi
                .exportExternalExchangeRecords({
                    projectSubCategory: this.queryForm.condition.projectSubCategory,
                    studentFaculty: this.queryForm.condition.studentFaculty,
                    studentProfession: this.queryForm.condition.studentProfession,
                    projectNationCode: this.queryForm.condition.projectNationCode,
                    projectCollegeId: this.queryForm.condition.projectCollegeId,
                    projectStartTimeStr: this.queryForm.condition.projectStartTimeStr,
                    projectEndTimeStr: this.queryForm.condition.projectEndTimeStr,
                    studentParam: this.queryForm.condition.studentParam,
                    participantPass: this.queryForm.condition.participantPass,
                    applyStatus: this.queryForm.condition.applyStatus,
                    backApplyStatus: this.queryForm.condition.backApplyStatus,
                    projectMngmtName: this.queryForm.condition.projectMngmtName,
                    applyIds: applyIdList
                })
                .then(res => {
                    if (res.code === 200 && res.data.key) {
                        this.$refs.downloadRef.close()
                        this.exportButton = false
                        this.batchNormalDelayRequest(res.data.key)
                    }
                })
                .catch(e => {
                    this.$refs.downloadRef.close()
                    this.exportButton = false
                })
        },
        // 查看出国
        selectGoAbroad(row) {
            this.applyId = row.applyId
            this.projectSubCategory = row.projectSubCategory
            this.indexKey = 2
        },
        // 回到列表页
        changeProjectIndex() {
            this.indexKey = 1
            this.multipleSelection = []
            this.onSubmit()
        },
        // 查看回国报销
        selectReturnHome(row) {
            this.applyId = row.applyId
            this.projectStartTime = row.projectStartTime
            this.projectEndTime = row.projectEndTime
            this.projectSubCategory = row.projectSubCategory
            this.backId = ''
            this.tabTitle =
                row.projectSubCategory === 6
                    ? this.$t('projectApplication.nationGovernGoHomeReportSelect')
                    : this.$t('projectApplication.shortTermVisitRuturnGovernSelect')
            if (row.projectSubCategory === 6) {
                this.showProcess = false
            } else {
                this.showProcess = true
            }
            if (row.back) {
                this.backId = row.back.backId
            }
            this.indexKey = 3
        }
    },
    watch: {
        auths: {
            handler(newVal) {
                if (newVal && Array.isArray(newVal) && newVal.length > 0) {
                    newVal.some(item => {
                        // 导出
                        if (item.authCode === 'internCommuni-project-audit-export') {
                            this.permitToExport = true
                        }
                        // 查看
                        if (item.authCode === 'internCommuni-project-audit-export') {
                            this.permitToSelectGoAbroad = true
                        }
                    })
                }
            },
            deep: true,
            immediate: true
        }
    }
}
</script>
<style lang="scss" scoped>
.condition-title {
    color: #2b3b4e;
    font-size: 18px;
    line-height: 24px;
    font-weight: bold;
}
.sub-title {
    margin: 16px 0;
    font-size: 16px;
    color: #000020;
    letter-spacing: 0;
}
.project-manage-container ::v-deep {
    .el-dialog__body {
        word-break: break-all !important;
    }
}
</style>
